package command

import (
	"com.mgface.disobj/datanode/api"
	"com.mgface.disobj/datanode/server"
	"github.com/urfave/cli"
)

//todo 1.读取配置文件，覆盖默认值

//todo 2.根据配置文件来初始化文件存储还是缓存存储数据

//todo 3.判断如果是启用文件存储，启动的时候需要加载已有的文件数据

var startflag = []cli.Flag{
	cli.StringFlag{
		Name:     "na", //node address
		Usage:    "节点地址(node addres)",
		Required: true,
	},
	cli.StringFlag{
		Name:     "mna", //metanode address
		Usage:    "元数据服务节点地址(metanode address)",
		Required: true,
	},
	cli.StringFlag{
		Name:     "sdp", //store data path
		Usage:    "数据存储路径(store data path)",
		Required: true,
	},
	//todo 配置文件要单独处理
	cli.StringFlag{
		Name:     "file",
		Usage:    "配置文件",
		Required: false,
	},
}
var StartDNCommand = cli.Command{
	Name:    "start",
	Aliases: []string{"st"},
	Usage: `示例指令:
		startdatanode start -na 127.0.0.1:5000 -mna 127.0.0.1:3001 -sdp C:\\objects
		`,
	Flags: startflag,
	Action: func(ctx *cli.Context) error {

		//获得节点的数据存储地址
		sdp := ctx.String("sdp")
		//获得节点的地址
		na := ctx.String("na")
		//获得元数据服务节点地址
		mna := ctx.String("mna")
		//初始化数据
		api.Initval(sdp, na, mna)
		//启动服务
		server.StartServer(na, mna)
		return nil
	},
}
